package com.ahcfl.service.impl;

import com.ahcfl.dao.StudentMapper;
import com.ahcfl.dto.PageBean;
import com.ahcfl.pojo.Student;
import com.ahcfl.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<String> findAllStudentNames() {
        return studentMapper.findAllStudentNames();
    }

    @Override
    public void addStudent(String stuName) {
        studentMapper.addStudent(stuName);
    }

    @Override
    public PageBean<Student> findAllStudents(int pageNum,int pageSize,String name) {


        int total = studentMapper.findAllStudentsCount(name);

        int start = (pageNum-1)*pageSize;
        List<Student> studentList = studentMapper.findAllStudents(start,pageSize,name);
        PageBean<Student> pageBean = new PageBean<>(studentList,total);

        return pageBean;
    }

    @Override
    public void updateStudentScoreById(int id, int score) {
        studentMapper.updateStudentScoreById(id,score);
    }
}
